import { defineConfig, loadEnv } from "vite";
import laravel from "laravel-vite-plugin";
import vue from "@vitejs/plugin-vue";
import path from "path";

export default defineConfig(({ mode }) => {
	const env = loadEnv(mode, process.cwd(), '');
	return {
		plugins: [
			laravel({
				input: ["resources/js/app.js", "resources/css/app.css"],
				refresh: true,
			}),
			vue(),
		],
		resolve: {
			alias: {
				"@": "/resources/js",
				"@images": "/resources/images",
				ziggy: path.resolve("vendor/tightenco/ziggy/dist/index.es.js"),
			},
		},
		define: {
			'import.meta.env.VITE_API_KEY': JSON.stringify(env.VITE_API_KEY),
			'import.meta.env.VITE_SECURITY_JS_CODE': JSON.stringify(env.VITE_SECURITY_JS_CODE)
		},
		server: {
			host: 'localhost',
			port: 5173,
			hmr: {
				host: 'localhost',
				port: 5173
			},
			cors: {
				origin: ['http://localhost:8081'],
				methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
				credentials: true
			}
		},
	}
});
